<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
 
// import Joomla modelitem library
jimport('joomla.application.component.modelitem');

class ShopModelCategory extends JModelItem
{

	protected function populateState($ordering = null, $direction = null)
	{
		// Initiliase variables.
		$app	= JFactory::getApplication('site');
	
		// Load the parameters. Merge Global and Menu Item params into new object
		$params = $app->getParams();
		$menuParams = new JRegistry;

		if ($menu = $app->getMenu()->getActive()) {
			$menuParams->loadString($menu->params);
		}

		$mergedParams = clone $menuParams;
		$mergedParams->merge($params);

		$this->setState('params', $mergedParams);
		$user		= JFactory::getUser();
		// Create a new query object.
		//$this->setState('category.id', $params->get('cid'));
		$this->setState('category.id', JRequest::getVar('id'));
		$this->setState('product.isnew',$params->get('isnew',0));
		$this->setState('product.issale',$params->get('issale',0));
		$this->setState('product.islot',$params->get('islot',0));
		$this->setState('product.widthimg',$params->get('widthimg',100));
		$this->setState('product.heightimg',$params->get('heightimg',80));
		$this->setState('product.price',$params->get('price',1));
		$this->setState('product.oldprice',$params->get('oldprice',1));
		$this->setState('product.introtext',$params->get('introtext',1));
		$this->setState('product.numberword',$params->get('numberword',10));
		$this->setState('product.button',$params->get('button',1));
		$this->setState('page.columns',$params->get('columns',3));
		$this->setState('page.show_page_heading',$params->get('show_page_heading',0));
		$this->setState('page.page_title',$params->get('page_title','No Title'));
		$this->setState('sort',$params->get('sort','id'));
		$this->setState('product.item_display',$params->get('item_display',6));
		$this->setState('sortdir',$params->get('sortdir','DESC'));
				
	}
	/*
	*	get item products
	*	call get item products
	*/
	function getItems()
	{
		$catid = $this->getState('category.id');
		$db =& JFactory::getDBO();
		$query = $db->getQuery(true);
		$query->clear();
		$query->select('*');
		$query->from('#__shop_product');
		$query->where(" catid  in ( $catid )");
		$query->where("state = 1");
		$db->setQuery((string)$query);
		$items = $db->loadObjectList();
		return $items;
	}
	
}